<div id="app">
    <admin-page-header>
        <bi-button icon="fa-plus" @click="add"  type="primary">创建会员</bi-button>
    </admin-page-header>


    <div class="container">
        <div class="row g-2">
            <div class="col-12">
                <bi-card title="搜索">
                    <div class="row g-3">
                        <div class="col-12 col-sm-6 col-lg-6">
                             <bi-select v-model="search.status" placeholder="状态" :option="$pageData.statusOption" ></bi-select>
                        </div>
                        
                        <div class="col-12 col-sm-6 col-lg-6">
                            <bi-input v-model="search.keyword"  placeholder="用户手机号" icon="fa fa-search" ></bi-input>
                        </div>
                    </div>
                </bi-card>
            </div>
            <div class="col-12">
                <bi-card title="会员列表">
                    <bi-table :data="list" :loading="loading"  min-height="300" >
                        <bi-table-column label="ID" name="member_id" width="80"></bi-table-column>
                        <bi-table-column label="手机号" name="mobile" width="120" ></bi-table-column>
                        <bi-table-column label="最后登陆时间" name="last_login_date" ></bi-table-column>
                        <bi-table-column label="操作" width="120" v-slot="{row}">

                            <template v-if="row.status!='sale'">
                                <bi-button type="primary" @click="$go({action:'edit',gets:{id:row.goods_id}})">编辑</bi-button>
                                <bi-button type="warning" @click="handleDel(row)" >删除</bi-button>
                            </template>
                            <template v-else>
                                <bi-button type="danger" @click="handleOff(row)" >下架</bi-button>
                            </template>
                        </bi-table-column>
                    </bi-table>
                    <template #footer>
                        <bi-pagination v-model="page" :total="total" :count="count" ></bi-pagination>
                    </template>
                </bi-card>


            </div>
                
        </div>
    </div>

</div>


<script>
import {debounce} from '@@/admin/assets/js/global.js';

let app = admin.createApp({
    data(){
        let search  = {
            status:'',
            keyword:'',
        }


        this.$assign(search,this.$status.get('search'));

        return {
            search,
            list:[],
            loading:false,
            page:this.$status.get('page')??1,
            statusList:this.$pageData.statusList,
            total:0,
            count:0
        }
    },
    watch:{
        search:{
            handler:debounce(function(val){
                
                this.refresh();
            },1000),
            deep:true
        }       
    },
    methods:{
        refresh(){
            this.loading = true;

            this.$status.set('page',this.page);
            this.$status.set('search',this.search);

            this.$ajax({
                url:this.$url({action:'list'}),
                data:{
                    page_current:this.page,
                    ...this.search
                },
                success:(res)=>{
                     
                    this.list = res.list;
                    this.count  = res.count;
                    this.total =res.total;
                },
                over:()=>{
                    this.loading = false;
                }
            })
        },
    },
    mounted(){
        this.refresh();
    },
}).mount('#app');

</script>